package hip.util;

import lombok.extern.slf4j.Slf4j;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

@Slf4j
public class ScriptTest {
    public static void main(String[] args) {
        // 创建ScriptEngineManager对象
        ScriptEngineManager manager = new ScriptEngineManager();

        // 获取JavaScript引擎
        ScriptEngine engine = manager.getEngineByName("JavaScript");

        // 定义JavaScript代码
        String jsCode = "var data=[{\"topic\":\"patient-notice\",},[\"675d6c8fe05d8700019bf439\"]];JSON.stringify(data);";
        try {
            // 执行JavaScript代码
            Object result = engine.eval(jsCode);

            // 输出结果
            System.out.println("JavaScript执行结果: " + result.toString());
        } catch (ScriptException e) {
            log.error("执行出错:{}", e.getMessage());
        }
    }
}
